﻿@* ReSharper disable RedundantNameQualifier *@
@inherits System.Web.Mvc.WebViewPage<MvcControls.Controls.DataGrid.DataGridRenderInfo>
@* ReSharper restore RedundantNameQualifier *@
@{
    string gridName = Model.Name;
}
<div id="@gridName" style="border: 1px dotted black;">
    @Model.EditModule.RenderInitializeCode()
    <div>
        @* ReSharper disable AccessToForEachVariableInClosure *@
        @foreach (var button in Model.PanelControls)
        {
            @button
        }
        @* ReSharper restore AccessToForEachVariableInClosure *@
    </div>
    <table data-grid-id="Table" style="width: @Model.Width;">
        <thead>
            <tr>
                @Model.EditModule.RenderCommandColumnHeader()
                @foreach (var column in this.Model.Columns)
                {
                    <th data-grid-columnid="@Html.AttributeEncode(column.Name)">@Html.Encode(column.DisplayText)</th>
                }
            </tr>
        </thead>
        <tbody>
            @Model.EditModule.RenderNewLineRow()
            @* render hidden row template *@
            <tr data-grid-id="RowTemplate" style="display: none;">
                @Model.EditModule.RenderCommandCell()
                @for (int i = 0; i < this.Model.DataSource.Count; i++)
                {
                    <td />
                }
            </tr>
            @* render normal rows *@
            @foreach (var row in this.Model.DataSource)
            {                
                <tr data-grid-rowid="@Model.EditModule.RenderRowId(row)">
                    @Model.EditModule.RenderCommandCell()
                    @foreach (var column in this.Model.Columns)
                    {
                        if (column.PropertyValueSelector != null)
                        {
                            <td>@Html.Encode(column.PropertyValueSelector(row))
                            </td>
                        }
                        else
                        {
                            <td>@column.HtmlRenderer(row)
                            </td>
                        }
                    }
                </tr>
            }
        </tbody>
    </table>
</div>
